﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StoreManagementSystem.DomainObjects;

namespace StoreManagementSystem.DataAccessLayer
{
    [Serializable]
    public class SQLDAOFactory
    {
        private ISQLDataProvider DataProvider {get; set;}
        private string Connection { get; set; }
        private Dictionary<string, IDataAccessObject<Entity>> dict = new Dictionary<string, IDataAccessObject<Entity>>();

        public SQLDAOFactory(ISQLDataProvider dataProvider, string connection)
        {
            DataProvider = dataProvider;
            Connection = connection;
        }

        public IDataAccessObject<Entity> createDAO(string dao)
        {
            switch (dao)
            {
                case "category":
                    {
                        if (dict.ContainsKey(dao))
                            return dict[dao];
                        else
                        {
                            dict[dao] = new SQLCategoryDAO(DataProvider, Connection);
                            return dict[dao];
                        }
                    }

                case "brand":
                    {
                        if (dict.ContainsKey(dao))
                            return dict[dao];
                        else
                        {
                            dict[dao] = new SQLBrandDAO(DataProvider, Connection);
                            return dict[dao];
                        }
                    }

                case "aisle":
                    {
                        if (dict.ContainsKey(dao))
                            return dict[dao];
                        else
                        {
                            dict[dao] = new SQLAisleDAO(DataProvider, Connection);
                            return dict[dao];
                        }
                    }

                case "product":
                    {
                        if (dict.ContainsKey(dao))
                            return dict[dao];
                        else
                        {
                            dict[dao] = new SQLProductDAO(DataProvider, Connection);
                            return dict[dao];
                        }
                    }

                case "storeuser":
                    {
                        if (dict.ContainsKey(dao))
                            return dict[dao];
                        else
                        {
                            dict[dao] = new SQLStoreUserDAO(DataProvider, Connection);
                            return dict[dao];
                        }
                    }
            }
            return null;
        }
    }
}